package com.nuorui.module.system.controller;

import com.nuorui.common.constant.AdminSwaggerTagConst;
import com.nuorui.common.core.domain.ResponseDTO;
import com.nuorui.module.system.domain.form.RoleMenuForm;
import com.nuorui.module.system.domain.vo.RoleMenuTreeVO;
import com.nuorui.module.system.service.RoleMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 角色关联菜单
 *
 * @author: Fred
 * @email 453086@qq.com
 * @create: 2021-10-22 10:42
 */
@RestController
@RequiredArgsConstructor
@Api(tags = AdminSwaggerTagConst.System.SYSTEM_ROLE_MENU)
public class RoleMenuController {

    private final RoleMenuService roleMenuService;

    @GetMapping("/roles/{roleId}/menus")
    @ApiOperation(value = "获取角色的菜单权限树", notes = "根据角色ID获取其拥有的菜单权限树")
    public ResponseDTO<RoleMenuTreeVO> getMenuTreeByRoleId(@PathVariable Long roleId) {
        return roleMenuService.getMenuTreeByRoleId(roleId);
    }

    @PutMapping("/roles/{roleId}/menus")
    @ApiOperation(value = "更新角色的菜单权限", notes = "为指定角色更新其菜单权限")
    public ResponseDTO<String> updateRoleMenu(@PathVariable("roleId") Long roleId, @Valid @RequestBody RoleMenuForm roleMenuForm) {
        return roleMenuService.updateRoleMenu(roleId,roleMenuForm);
    }
}
